<title>用户管理</title>
<#include "../common/common.html"/>

<div class="page-header">
	<h1>
		${user.id?? ? string('修改','添加')}用户
	</h1>
</div>

<div class="row">
	<div class="col-xs-12">
		<!-- PAGE CONTENT BEGINS -->
		<form id="_editForm" class="form-horizontal" role="form" 
			validate="true">
			<input type="hidden" name="id" value="${user.id!}">
			
			<div class="form-group">
				<label for="_officeId" class="col-sm-3 control-label no-padding-right"><span class="form-star">*</span>机构</label>

				<div class="col-sm-3">
					<select id="_officeId" name="officeId" class="form-control help-validate" required="true">
						<option value="">请选择</option>
						<#list officeList as item>
							<option value="${item.id}" <#if user.officeId?? && user.officeId == item.id>selected="selected"</#if>>${item.name}</option>
						</#list>
					</select>
				</div>
			</div>
			
			<div class="form-group">
				<label for="_name" class="col-sm-3 control-label no-padding-right">姓名</label>

				<div class="col-sm-6">
					<div class="clearfix help-validate">
						<input id="_name" name="name" type="text" value="${user.name!}" class="form-data col-xs-10 col-sm-5" placeholder="名称"
							maxlength="50"/>
					</div>
				</div>
				
			</div>
			
			<div class="form-group">
				<label for="_account" class="col-sm-3 control-label no-padding-right"><span class="form-star">*</span>登录名</label>

				<div class="col-sm-9">
					<div class="input-medium help-validate">
						<div class="input-group">
							<input id="_account" name="account" type="text" value="${user.account!}" class="form-data"
								ajax="{url : '${request.contextPath}/admin/user/validate-account', dataId : '_editForm'}"
								required="true" minlength = '4' maxlength = '64'/>
							<span class="input-group-addon">
								<i class="ace-icon fa fa-user"></i>
							</span>
						</div>
					</div>
				</div>
				
			</div>
			
			<div class="form-group">
				<label for="_password" class="col-sm-3 control-label no-padding-right">${user.id?? ? string('','<span class="form-star">*</span>')}密码</label>
				
				<div class="col-sm-9">
					<div class="input-medium help-validate">
						<div class="input-group">
							<input id="_password" name="password" type="password" value="" class="form-data"
								${user.id?? ? string('data-rel="tooltip" title="不修改请留空"','')}
								${user.id?? ? string('','required="true"')}
								minlength = '6' maxlength = '16'/>
							<span class="input-group-addon">
								<i class="ace-icon fa fa-lock"></i>
							</span>
						</div>
					</div>
				</div>
			</div>
			
			<div class="form-group">
				<label class="control-label col-xs-12 col-sm-3 no-padding-right"><span class="form-star">*</span>是否启用</label>

				<div class="col-xs-12 col-sm-9">
					<div class="clearfix help-validate">
						<div>
							<label class="line-height-1 blue">
								<input name="isEnable" value="true" type="radio" class="ace" ${(user.isEnable?? && user.isEnable) ? string('checked="checked"','')}/>
								<span class="lbl"> 是</span>
							</label>
						</div>
	
						<div>
							<label class="line-height-1 blue">
								<input name="isEnable" value="false" type="radio" class="ace" ${(user.isEnable?? && user.isEnable) ? string('','checked="checked"')}/>
								<span class="lbl"> 否</span>
							</label>
						</div>
					</div>
				</div>
			</div>
			
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button id="_submit" type="button" class="btn btn-info" data-loading-text="正在提交...">
						<i class="ace-icon fa fa-check bigger-110"></i>
						提交
					</button>

					&nbsp; &nbsp; &nbsp;
					<button id="_cancle" class="btn" type="reset">
						<i class="ace-icon fa  fa-times bigger-110"></i>
						取消
					</button>
				</div>
			</div>
		</form>

	</div>
</div>

<script type="text/javascript">
	$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
		jQuery(function($) {
			//焦点
			$("#_account").focus();
			
			//帮助查看
			$('[data-rel=tooltip]').tooltip({container:'body'});
			
			// 提交
			$("#_submit").click(function(){
				if($('#_editForm').validate()){
					var btn = $(this);
					btn.button('loading');
					$.post("${request.contextPath}/admin/user/save", $.formJson('_editForm'),function(d) {
						if(d){
							btn.button('reset');
							if(d.code == 1){
								$.aceRedirect("${request.contextPath}/admin/user");
							}
							else {
								$.gritter.add({text: d.message});
							}
						}
			        },'json');
				}
			});
			
			// 取消
			$("#_cancle").click(function(){
				$.aceRedirect("${request.contextPath}/admin/user");
			});
			
			// 回车绑定
			$(".form-data").bind('keypress',function(event){
                if(event.keyCode == "13"){
                	event.preventDefault();
                	$("#_submit").click();
                }
            });
		});
	});
</script>
